#include <unistd.h>
#include <sys/wait.h>

int real_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options, void *);

int main() {
    char command[255];

    for (;;) {
        write(1, "root@pc:~# ", sizeof("root@pc:~# "));
        int count = read(0, command, 255);

        // bin/ls\n -> bin/ls\0
        command[count - 1] = 0;

        pid_t fork_result = fork();

        // 子进程
        if (fork_result == 0) {
            execve(command, 0, 0);
            break;
        }
        // 父进程
        else {
            siginfo_t info;

            // P_ALL  等待所有子进程结束
            real_waitid(P_ALL, 0, &info, WEXITED, 0);
        }
    }

    _exit(0);
}
